package com.gjh.study.mybatis.mapper2;

import com.gjh.study.mybatis.domain.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

/**
 * @author guangjh
 * @version 1.0
 * @date 2020/7/12 7:40
 */
public interface UserMapper {
    @Select("select * from tb_user where id = #{id}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "loginname", column = "loginname"),
            @Result(property = "password", column = "password"),
            @Result(property = "phone", column = "phone"),
            @Result(property = "address", column = "address"),
            @Result(property = "orders", column = "id",
                    many = @Many(select = "com.gjh.study.mybatis.mapper2.OrderMapper.selectOrderByUserId", fetchType = FetchType.LAZY)),
    })
    User selectUserById(int id);
}
